#!/usr/bin
# -*- coding: utf-8 -*-

import mod_parameters as params
from numpy import array as nparray

TCI = params.PARAMS["testConstructorsInputs"]
FLOAT = params.PARAMS["float"]



# ==============================================================================
class Node():
    NCOORDS = None
    TYPE = None

    def __init__(self, uId, x):
        if TCI:
            self.testInputs(uId, x)
        self.uId = uId
        self.x = nparray(x, dtype=FLOAT)

    def testInputs(self, uId, x):
        if not isinstance(uId, str):
            raise ValueError
        if not len(x) == self.NCOORDS:
            raise ValueError, "A " + self.TYPE + " node needs " + \
                              str(self.NCOORDS) + " coordinates"

    def __str__(self):
        a = "Node " + self.TYPE + ":\n"
        a += "- user id: " + str(self.uId) + "\n"
        a += "- coordinates: " + str(self.x)
        return a



# ==============================================================================
class Node3D(Node):
    """ A node does not have any name.
    Its collection manage that. """
    NCOORDS = 3
    TYPE = "3D"

    def __init__(self, uId, x):
        Node.__init__(self, uId, x)



# ==============================================================================
if __name__ == "__main__":
    myNode = Node3D("n1", (0., 1., 2.))
    print myNode
